<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Controllers/AdminController.php';
  require_once '../../Controllers/UserController.php';
  require_once '../../Helpers/PathHelper.php';
  //
  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //
  $c = new AdminController();
  $yearLevelList = $c->getYearLevel();
  $year = $c->getYearLevelByDepartment(1);

  if(isset($_POST['view-subjects']) && !empty($_POST['view-subjects']))
  {
    $yid = $_POST['year'];
    $subjectList = $c->getSubjectListByYear($yid);
  }
  else {
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';

    $query = "INSERT INTO "
  }

?>
<html>
  <head>
    <title>School Enrollment :: Input Grades</title>
    <?php
      require_once '../commons.php';
      renderHeaderStyles() ;
    ?>  </head>
  <div class="container">
    <?php renderAdminNav(); ?>
    <h1>Input Grades</h1>
    <form name="year-level-form" method="post">
      <label for="year-level">Choose a year level: </label>
      <select name="year">
        <?php
          if(mysql_num_rows($yearLevelList) < 1)
            echo "<option value='0'>No data available</option>";

          while($rows=mysql_fetch_assoc($yearLevelList))
          {
            $i = $rows['YearLevelId'];
            $n = $rows['YearLevelDescription'];
            echo "<option value='$i'>$n</option>";
          }
        ?>
      </select><br /><br />
      <input type="submit" name="view-subjects" value="View Subjects" />
    </form>
    <hr />
    <div class="inner">
      <form name="grades-form" method="post">
		    <label for="student-name">Student ID:</label>
  		  <input type="text" name="student-id" /><br /><br />
        <table align="center" class="inner card" border="1">
        <tr>
          <th width="400">LEARNING AREAS</th>
          <th colspan="5">Grading Period</th>
        </tr>
        <tr>
          <td width="200">&nbsp;</td>
          <td width="50">1st grading</td>
          <td width="50">2nd grading</td>
          <td width="50">3rd grading</td>
          <td width="50">4th grading</td>
          <td width="50">Final Rating</td>
        </tr>
        <?php
          if(mysql_num_rows($subjectList) < 1)
            echo '<tr><td colspan="5">NO SUBJECTS AVAILABLE.</td></tr><tr><td>&nbsp;</td></tr>';
          //
          while($rows=mysql_fetch_assoc($subjectList))
          {
            $content = '';
            //
            $subjectName = $rows['SubjectName'];
            $id = $rows['SubjectId'];
            $aSubject = explode(" ",$subjectName);
            $subject = implode('_',$aSubject);
            //
            $content .='<tr><td>'.$subjectName.'</td>';
            $content .='<td width="50"><input type="text" name="'.$id.'[1]" /></td>';
            $content .='<td><input type="text" name="'.$id.'[2]" /></td>';
            $content .='<td><input type="text" name="'.$id.'[3]" /></td>';
            $content .='<td><input type="text" name="'.$id.'[4]" /></td>';
            $content .='<td><input type="text" name="'.$id.'[5]" /></td></tr>';
            //
            echo $content;
          }
        ?>
        <tr>
          <td>GENERAL AVERAGE</td>
          <td><input type="text" name="grading[1]" /></td>
          <td><input type="text" name="grading[2]" /></td>
          <td><input type="text" name="grading[3]" /></td>
          <td><input type="text" name="grading[4]" /></td>
          <td><input type="text" name="grading[5]" /></td>
        </tr>
        <t>
      </table><br /><br />
      <input type="submit" name="save-grades" value="Save Grades" />
      </form>
		</div><!--end of inner-->
  </div>
</html>